package com.handinglian.ai.common.dto;

import lombok.Data;

/**
 * @author handinglian
 * @description
 * @date 2019/4/12 15:26
 */
@Data
public class ResultData<T> {
    /**
     * 字段码
     */
    private Integer code;

    /**
     * 描述
     */
    private String description;

    /**
     * 返回数据
     */
    private T data;

    public ResultData() {
    }

    public ResultData(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    public ResultData(Integer code, String description, T data) {
        this.code = code;
        this.description = description;
        this.data = data;
    }

    /**
     * 成功返回结果
     *
     */
    public static <T> ResultData success() {
        return new ResultData(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), null);
    }

    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     */
    public static <T> ResultData success(T data) {
        return new ResultData(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }

    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     * @param  message 提示信息
     */
    public static <T> ResultData<T> success(T data, String message) {
        return new ResultData<T>(ResultCode.SUCCESS.getCode(), message, data);
    }

    /**
     * 失败返回结果
     * @param errorCode 错误码
     */
    public static <T> ResultData<T> failed(IErrorCode errorCode) {
        return new ResultData<T>(errorCode.getCode(), errorCode.getMessage(), null);
    }

    /**
     * 失败返回结果
     * @param message 提示信息
     */
    public static <T> ResultData<T> failed(String message) {
        return new ResultData<T>(ResultCode.FAILED.getCode(), message, null);
    }

    /**
     * 失败返回结果
     */
    public static <T> ResultData<T> failed() {
        return failed(ResultCode.FAILED);
    }

    /**
     * 登录失败
     */
    public static <T> ResultData<T> loginFailure(String message) {
        return new ResultData<T>(ResultCode.LOGIN_FAILURE.getCode(), message, null);
    }

    /**
     * 该账号已存在于历史员工库中
     */
    public static <T> ResultData<T> existsInHistory() {
        return new ResultData<T>(ResultCode.EXIST_IN_HISTORY.getCode(), ResultCode.EXIST_IN_HISTORY.getMessage(), null);
    }

    /**
     * 未登录
     */
    public static <T> ResultData<T> notLogin() {
        return new ResultData<T>(ResultCode.NOT_LOGIN.getCode(), ResultCode.NOT_LOGIN.getMessage(), null);
    }

    /**
     * 授权失败
     */
    public static <T> ResultData<T> authorize() {
        return new ResultData<T>(ResultCode.AUTHORIZE_FAIL.getCode(), ResultCode.AUTHORIZE_FAIL.getMessage(), null);
    }

    /**
     * 数据重复
     */
    public static <T> ResultData<T> duplicate() {
        return new ResultData<T>(ResultCode.DUPLICATE.getCode(), ResultCode.DUPLICATE.getMessage(), null);
    }

    /**
     * 退出成功
     */
    public static <T> ResultData<T> logout() {
        return new ResultData<T>(ResultCode.SUCCESS.getCode(), "登出成功", null);
    }


}
